﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;
using System.Windows.Threading;
using System.Threading;
using System.Net.Sockets;
using Microsoft.Phone.Controls;
using System.Xml.Linq;
using JsonTest1.Module;
using System.Windows.Resources;
using System.IO;


namespace JsonTest1.Network
{
    public class Call
    {
        public Call()
        {
 
        }

        private static PhoneApplicationPage page1;

        public static string BASE_URL = "http://weather.yahooapis.com/forecastrss?w=2172743&u=c";

        public static void Download(PhoneApplicationPage page)
        {
            page1 = page;
            WebClient client = new WebClient();
           client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wDownlosd);
           client.DownloadStringAsync(new Uri(BASE_URL));
        }

        public static void showDialog()
        {
            MessageBox.Show("CWebclient");
        }

        public static void wDownlosd(object sender, DownloadStringCompletedEventArgs e)
        {

            page1.Dispatcher.BeginInvoke(() => showDialog());

             StreamResourceInfo reader = Application.GetResourceStream(new Uri("/JsonTest1;component/Res/Students.xml", UriKind.Relative));
               StreamReader stringReader = new StreamReader(reader.Stream);

               ParserXml.parser(stringReader.ReadToEnd());

           /* try
            {
                

                XDocument doc = new XDocument();
                doc = XDocument.Parse(e.Result);

                bool forecastTomorrow = true;

                foreach (XElement element in doc.Descendants("channel").Descendants("item").Nodes())
                {
                    if (element.ToString().Contains("<yweather:forecast"))
                    {
                        string date = element.Attribute("date").Value;
                        string day = element.Attribute("day").Value;
                        string conditions = element.Attribute("text").Value;
                        string tempLow = element.Attribute("low").Value;
                        string tempHigh = element.Attribute("high").Value;
                        string code = element.Attribute("code").Value;

                        int weatherCode = Convert.ToInt16(code);
                        //string imageName = weatherImage(weatherCode);

                       // Uri uri = new Uri("Images/" + code + ".png", UriKind.Relative);
                       // ImageSource img = new BitmapImage(uri);


                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }*/
        }
    }
}
